package com.qingxin.park.action;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qingxin.park.entity.Video;
import com.qingxin.park.service.VideoService;
import com.qingxin.sys.action.BaseAction;
import com.qingxin.sys.mvc.PageParam;
import com.qingxin.sys.mvc.SysError;
/**
 * 视频管理
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/video")
public class VideoAction extends BaseAction {
	
	@Autowired
	private VideoService videoService;
	/**
	 * 列表
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/list.do", method=RequestMethod.GET)
	public String list(ModelMap model, HttpServletRequest request){
		return "trace/video/video_list";
	}

	/**
	 * 视频列表数据
	 * @param pageParam
	 * @param datatype
	 * @param search
	 * @param leftdata
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/listdata.json", method={RequestMethod.GET, RequestMethod.POST})
	@ResponseBody
	public Object listdataALL(PageParam pageParam,String datatype,String search,String leftdata,HttpServletRequest request){
		return videoService.list(pageParam,leftdata, getLoginUser(request), request);
	}
	
	/**
	 * 添加
	 * @param model
	 * @param leftdata
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/add.do", method=RequestMethod.GET)
	public String add(ModelMap model, String leftdata, HttpServletRequest request){
		model.put("parkid", leftdata);
		return "/trace/video/video_add";
	}
	
	/**
	 * 展示
	 * @param model
	 * @param leftdata
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/show.do", method=RequestMethod.GET)
	public String show(ModelMap model, String videoid, HttpServletRequest request){
		Video video = videoService.get(videoid);
		model.put("video", video);
		return "/trace/video/video_show";
	}
	
	/**
	 * 添加保存
	 * @param wellProduct
	 * @param result
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/save.json", method=RequestMethod.POST)
	@ResponseBody
	public Object save(@Valid Video video ,BindingResult result, HttpServletRequest request){
		if(result.hasErrors()){
			return getSysErrors(result);
		}		
		SysError info = videoService.add(video,getLoginUser(request), request);
		return info;
	}
	
	/**
	 * 删除
	 * @param productid
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/delete.json", method=RequestMethod.POST)
	@ResponseBody
	public Object delete(String[] videoid, HttpServletRequest request){
		return videoService.delete(videoid, request);
	}
	
	/**
	 * 修改
	 * @param model
	 * @param articleId
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/edit.do", method=RequestMethod.GET)
	public String edit(ModelMap model, String videoid, HttpServletRequest request){
		Video video = videoService.get(videoid);
		model.put("video", video);
		return "trace/video/video_edit";
	}
	
	/**
	 * 保存修改
	 * @param wellProduct
	 * @param result
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/update.json", method=RequestMethod.POST)
	@ResponseBody
	public Object update(@Valid Video video, BindingResult result, HttpServletRequest request){
		if(result.hasErrors()){
			return getSysErrors(result);
		}
		return videoService.update(video, getLoginUser(request), request);
	}
	
	
}
